package com.five.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;


/**
 * @author Ywt
 */
@Component
public class RedisUtil {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    // 基本操作
    public void set(String key, Object value) {
        redisTemplate.opsForValue().
                set(key, value,2, TimeUnit.MINUTES);
    }

    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    // 清理缓存
    public void clearCache(String key) {
        redisTemplate.delete(key);
    }
}